//
//  GetMenuTask.m
//  ZooNgonDoiOS
//
//  Created by Anh Jun Linh Tinh on 7/3/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "GetMenuTask.h"
#import "ZooMenuBean.h"
#import "RestKit/JSONKit.h"

@implementation GetMenuTask

-(id)initWithSpotId:(NSString *)spotId{
    self = [super init];
    if(self){
        _spotId = spotId;
    }
    return self;
}

-(void)doExcute{
    NSDictionary *params = [NSDictionary dictionaryWithKeysAndObjects:@"spot_id",_spotId,nil];
    [[RKObjectManager sharedManager].client get:@"/spot/menu" queryParameters:params delegate:self];
}

-(void)request:(RKRequest *)request didReceiveResponse:(RKResponse *)response{
    NSString *jsonString = [response bodyAsString];
    NSDictionary *json = [jsonString objectFromJSONString];
    NSNumber *status = [json objectForKey:@"status"];
    NSMutableArray *menuBeans = [[NSMutableArray alloc] init];
    if(status){
        NSArray *menuArray = [json objectForKey:@"data"];
        for (int i = 0, size = [menuArray count]; i < size; i++) {
            NSDictionary *row = [menuArray objectAtIndex:i];
            ZooMenuBean *menuBean = [[ZooMenuBean alloc] init];
            menuBean.idItem = [row objectForKey:@"id"];
            menuBean.spot_id = _spotId;
            menuBean.name = [row objectForKey:@"name"];
            [menuBeans addObject:menuBean];
        }
    }else{
        int errorCode = [[json objectForKey:@"error_code"] intValue];
    }
}

@end
